﻿@model IEnumerable<MvcAtletIS.Models.Performances>
@{
    ViewBag.Title = "Zoznam prihlásených pretekárov";
}

<h2>Zoznam prihlásených pretekárov</h2>

<p>
    Vyberte preteky a disciplínu, pre ktorú chcete zobraziť zoznam prihlásených pretekárov.
</p> 

@using (Html.BeginForm())
{   
    <div class="filter-frame">
        
        <div class="filter-item">
            <div class="editor-label">
                Preteky
            </div>
            <div class="editor-field">
                @Html.DropDownList("CompetitionId", null, "Vyberte preteky", new { onchange = "this.form.submit();" })
            </div>
        </div>
    
        <div class="filter-item">
            <div class="editor-label">
                Disciplína
            </div>
            <div class="editor-field">
                @Html.DropDownList("DisciplineListId", null, "Vyberte disciplínu", new { onchange = "this.form.submit();" })
            </div>
        </div> 
    
    </div>   
}

<p></p>

@if ((Model != null) & Model.Count() > 0)
{ 
    <table width="100%"> 
        <tr>
            <th width="200px">
                Priezvisko
            </th>
            <th width="100px">
                Meno
            </th>
            <th width="100px">
                Dátum
            </th>
            <th width="200px">
                Klub
            </th>
            <th width="200px">
                Krajina
            </th>
            <th>
                SB
            </th>
        </tr>

    @foreach (var item in Model)
    { 
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Surname)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.FirstName)
            </td>
            <td align="right">
               @Html.DisplayFor(modelItem => item.Birthdate)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Club)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Countries.Name)
            </td>
            <td align="right">
                @Html.DisplayFor(modelItem => item.SB)
            </td>
        </tr>
    }
    </table>
    <p>
        Počet prihlásených pretekárov: @Model.Count()
    </p>
}

<script type="text/javascript">
    $(document).ready(function () {
        $("#CompetitionId").change(function () {
            var idCompetition = $(this).val();
            $.getJSON("/Signups/LoadDisciplinesForCompetition", { id: idCompetition },
            function (competitorsData) {
                var select = $("#DisciplineListId");
                select.empty();
                select.append($('<option/>',
                {
                    value: 0,
                    text: "Vyberte disciplínu"
                }));
                $.each(competitorsData, function (index, itemData) {
                    select.append($('<option/>',
                    {
                        value: itemData.Value,
                        text: itemData.Text
                    }));
                });
            });
        });
    });
</script>